import {Component, OnInit} from '@angular/core';
import {CommonTool} from '../../common/common.tool';
import {FileManagementService} from '../file-management/file-management.service';
import {BUTTON_CODE} from '../../config/button-code';

@Component({
  selector: 'app-default-page',
  templateUrl: './default-page.component.html',
  styleUrls: ['./default-page.component.scss']
})
export class DefaultPageComponent implements OnInit {

  public userDiskInfo: { freeFlow, cloudSpace, useSpace };
  public BUTTON_CODE = BUTTON_CODE;

  constructor(private fileManagementService: FileManagementService) {
    this.userDiskInfo = {
      freeFlow: '0kb',
      cloudSpace: '0kb',
      useSpace: '0kb'
    };
  }

  ngOnInit() {
    this.fileManagementService.getUserDiskInfo().subscribe(res => {
      this.userDiskInfo = {
        freeFlow: CommonTool.getSpaceUnit(res.freeFlow),
        cloudSpace: CommonTool.getSpaceUnit(res.cloudSpace),
        useSpace: CommonTool.getSpaceUnit(res.useSpace)
      };
    });
  }
}
